package com.itheima.Test;

import com.itheima.dao.ContactDao;
import com.itheima.dao.impl.ContactImpl;
import com.itheima.domain.Contact;
import com.itheima.domain.ContactCondition;
import com.itheima.domain.User;
import org.junit.Test;

import java.sql.Date;
import java.sql.SQLException;
import java.time.Instant;

public class ContactTest {
    ContactDao contactDao = new ContactImpl();

    @Test
    public void query() throws SQLException {
        System.out.println(contactDao.queryAll());
    }

    @Test
    public void addUser() throws SQLException {
        for (int i = 0; i < 10; i++) {
            Contact contact = new Contact();
            contact.setName("tom" + i);
            contact.setSex("男");
            contact.setAge(i);
            contact.setAddress("address" + i);
            contact.setQq("179235517" + i);
            contact.setEmail("179235517@qq.con");
            Date date = new Date(new java.util.Date().getTime());
            contact.setCreateDate(date);
            contactDao.add(contact);
        }

    }

    @Test
    public void deleteUser() throws SQLException {
        Contact contact = new Contact();
        contact.setId(5);
        contact.setName("saber");
        contact.setSex("女");
        contact.setAge(18);
        contact.setAddress("address");
        contact.setQq("179235517");
        contact.setEmail("179235517@qq.con");
        Date date = new Date(new java.util.Date().getTime());
        contact.setCreateDate(date);
        System.out.println(contactDao.update(contact));
    }

    @Test
    public void deleteById() throws SQLException {
        System.out.println(contactDao.delete(3));
    }

    @Test
    public void queryById() throws SQLException {
        System.out.println(contactDao.queryById(1));
    }

    @Test
    public void queryForPageTotalCount() throws SQLException {
        System.out.println(contactDao.queryForPageTotalCount());
    }

    @Test
    public void queryForPageItems() throws SQLException {
        System.out.println(contactDao.queryForPageItems(2, 2));
    }

    @Test
    public void queryForCondition() throws SQLException {
        ContactCondition cc = new ContactCondition();
        cc.setNameLike("c");
        cc.setFromAge(10);
        cc.setToAge(20);
        contactDao.queryForCondition(cc);
    }
}
